<?php
/**
 * 优惠卡-用户管理
 * @copyright (c) Seer All Rights Reserved
 */

require_once 'globals.php';

$Card_Model = new Card_Model();
$action = $_POST['action'];
$mode = $_POST['mode'];
$wx_openid = isset($_REQUEST['wx_openid']) ? $_REQUEST['wx_openid'] : '';
$card_id = isset($_REQUEST['card_id']) ? $_REQUEST['card_id'] : '';

$user_name = isset($_REQUEST['user_name']) ? $_REQUEST['user_name'] : '';
$card_name = isset($_REQUEST['card_name']) ? $_REQUEST['card_name'] : '';

$page = $_GET['pid'] ? $_GET['pid'] : '1';

$addUrl = $wx_openid ? "wx_openid={$wx_openid}&" : '';
$addUrl .= $card_id ? "card_id={$card_id}&" : '';
$addUrl .= $page ? "pid={$page}&" : '';
$addUrl .= $user_name ? "user_name={$user_name}&" : '';
$addUrl .= $card_name ? "card_name={$card_name}&" : '';

//显示优惠卡-用户(优惠卡-用户一览表检索)
if ($action == '' ) {

	$sqlSegment .= ' ORDER BY buildtime DESC ';
	$pwd = '优惠卡一览';


	$ucsNum = $Card_Model->getUcsNum($wx_openid,$card_id);
	$ucs = $Card_Model->getUcsForAdmin($wx_openid,$card_id,$page);

	$pageurl =  pagination($ucsNum, Option::get('admin_perpage_num'), $page, "user_card_list.php?{$addUrl}");
 
	include View::getView('header');
	require_once View::getView('card/user_card_list');
	include View::getView('footer');View::output();
}

// 学生删除
if ($action == 'delete' ) {
	$ucs = isset($_POST['ids']) ? $_POST['ids'] : array();
	$Card_Model->deleteUc($ucs);
	seerDirect("./user_card_list.php?active_del=1&{$addUrl}");
}

// 学生信息编辑
if ($action == 'update') {;
	$ID = $_POST['ID'];
	$state = $_POST['state'];

	$Card_Model->updateUc($ID,$state);
	seerDirect("./user_card_list.php?active_update{$state}=1&{$addUrl}");
}
